# from django.shortcuts import render,redirect
# from web import models
# from django import forms
# from django.core.validators import   RegexValidator
# from django.core.exceptions import  ValidationError
# from django.utils.safestring import mark_safe
# #from app01.utils.pagination import Pagination
# from web.utils.pagination import Pagination
# from web.utils.bootstrap import BootstrapModelForm
#
# class UserModelForm(BootstrapModelForm):
#     name = forms.CharField(
#         min_length=3,
#         label="用户名",
#         widget=forms.TextInput(attrs={"class":"form-control"})
#     )
#     class Meta:
#         model = models.UserInfo
#         fields = ["name","password","age","account","create_time","gender","depart"]
#
#
# class PerrtyModelForm(BootstrapModelForm):
#     #验证：方式一
#     # mobile = forms.CharField(
#     #     label="手机号",
#     #     validators=[RegexValidator(r'^1[3-9]\d{9}$','手机号格式错误'),],
#     # )
#
#     class Meta:
#         model = models.PerrtyNum
#         #fields = ["mobile","price","level","status"]
#         fields = "__all__"
#         #exclude = ["level"]   #排除某个字段，其他全部写入列表
#
#
#     def clean_mobile(self):
#         txt_mobile = self.cleaned_data['mobile']
#
#         exists = models.PerrtyNum.objects.filter(mobile=txt_mobile).exists()
#         if exists:
#             raise ValidationError("手机号已经存在")
#
#         return txt_mobile
#
#
# class PerrtyEditModelForm(BootstrapModelForm):
#     # mobile = forms.CharField(disabled=True)
#     class Meta:
#         model = models.PerrtyNum
#         fields = ["mobile","price","level","status"]
#
#     def clean_mobile(self):
#         txt_mobile = self.cleaned_data['mobile']
#
#         #用于验证输入的手机号码是否已经存在于数据库中。这个方法看起来是用来避免在编辑或创建新对象时出现重复的手机号码。
#         exists = models.PerrtyNum.objects.exclude(id=self.instance.pk).filter(mobile=txt_mobile).exists()
#         if exists:
#             raise ValidationError("手机号已经存在")
#
#         return txt_mobile
#
#
